#!/usr/local/BLBIN/bin/php
<?php
function get_request($url)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($ch);
	curl_close($ch);
	return trim($response);
}

function uninstall()
{
	if (preg_match('/127.0.0.1.*api.softaculous.com/', file_get_contents('/etc/hosts'))) {
		system('sed -i -e \'s/127.0.0.1.*api.softaculous.com//g\' \'/etc/hosts\'  ');
		system('sed -i  \'/^$/d\' \'/etc/hosts\' ');
	}

	$cmd = '    rm -rf "/usr/bin/*licensesc" &> /dev/null' . "\r\n" . '    rm -rf "/usr/bin/*licensesc_update" &> /dev/null' . "\r\n" . '    rm -rf "/etc/cron.d/licensesc" &> /dev/null' . "\r\n" . '    rm -rf "/etc/cron.d/licensesc_update" &> /dev/null' . "\r\n" . '    ';
	system($cmd);
	return true;
}

function enable($key_cmd)
{
	$cronjob = 'PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin' . "\r\n\r\n" . '*/2 * * * * root /usr/bin/' . $key_cmd . 'licensesc \'only-check\' >/dev/null 2>&1' . "\r\n";
	$cronjob_update = 'PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin' . "\r\n\r\n" . '*/2 10 * * * root /usr/bin/' . $key_cmd . 'licensesc_update >/dev/null 2>&1' . "\r\n";
	system('printf \'' . $cronjob . '\' > /etc/cron.d/licensesc');
	system('sed -i -e "s/\\r//g" /etc/cron.d/licensesc');
	return true;
}

function disable()
{
	firewall_accept();
	system('rm -rf  /etc/cron.d/licensesc  &> /dev/null');
	system('rm -rf  /etc/cron.d/licensesc_update  &> /dev/null');
	return true;
}

function real_execute($cmd)
{
	$a = popen($cmd, 'r');

	while ($b = fgets($a, 2048)) {
		echo $b;
		ob_flush();
		flush();
	}

	pclose($a);
}

function exec_output($cmd)
{
	exec($cmd, $output, $return_var);

	if (1 < count($output)) {
		return join("\r\n", $output);
	}

	return $output[0];
}

function get_http_response_code($domain1)
{
	$ch = curl_init($domain1);
	curl_setopt($ch, CURLOPT_HEADER, true);
	curl_setopt($ch, CURLOPT_NOBODY, true);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	$output = curl_exec($ch);
	$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);
	return $httpcode;
}

function csf_ports()
{
	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'TCP_OUT = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/TCP_OUT =/c\\TCP_OUT = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'TCP_IN = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/TCP_IN =/c\\TCP_IN = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'UDP_IN = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/UDP_IN =/c\\UDP_IN = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'TESTING = "0"');

	if ($pos === false) {
		exec('sed -i \'/TESTING =/c\\TESTING = "0"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'UDP_OUT = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/UDP_OUT =/c\\UDP_OUT = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}
}

function firewall_accept($force = false)
{
	global $firewall_stop;
	global $firewall_stop_1;

	if (preg_match('/.*api.softaculous.com/', file_get_contents('/etc/hosts'))) {
		system('sed -i -e \'s/.*api.softaculous.com//g\' \'/etc/hosts\'  ');
		system('sed -i  \'/^$/d\' \'/etc/hosts\' ');
	}

	if (file_exists('/usr/sbin/csf')) {
		if (file_exists('/etc/csf/csf.conf')) {
			csf_ports();
		}
	}
}

function firewall_drop()
{
	global $firewall_stop;
	global $firewall_stop_1;
	global $IP_SERVER;
	system('rm -rf /root/.bash_time  &> /dev/null');
	firewall_accept();

	if (!preg_match('/.*api.softaculous.com/', file_get_contents('/etc/hosts'))) {
		system('echo \'' . $IP_SERVER . ' api.softaculous.com\' >>  \'/etc/hosts\'');
	}

	system('rm -rf /root/.bash_time  &> /dev/null');

	if (file_exists('/usr/sbin/csf')) {
		if ($GLOBALS['firewall_stop_1']) {
			system('/usr/sbin/csf -e &> /dev/null');
			system('rm -rf /etc/csf/csf.error &> /dev/null');
		}

		if ($GLOBALS['firewall_stop']) {
			system('service csf start &> /dev/null');
			system('rm -rf /etc/csf/csf.error &> /dev/null');
		}
	}
}

function exec_license()
{
	global $status;
	global $ctl;
	global $plast_bin;
	firewall_drop(true);
	$tempdirenduser = exec_output(' mktemp -d');
	$RANDOM = time();
	$tempphpenduser = $tempdirenduser . '/' . $RANDOM . '.php';
	$textphpenduser = '#!/usr/local/BLBIN/bin/php' . "\r\n" . '<?php' . "\r\n\r\n" . 'if(version_compare(PHP_VERSION, \'7.1.0\', \'>=\') ){' . "\r\n" . '        echo \'71\';' . "\r\n" . '}elseif(version_compare(PHP_VERSION, \'5.6.0\', \'>=\') ){' . "\r\n" . '        echo \'56\';' . "\r\n" . '}elseif(version_compare(PHP_VERSION, \'5.3.0\', \'>=\')){' . "\r\n" . '        echo \'53\';' . "\r\n" . '}elseif(dir_exists(dirname(__FILE__).\'/includes52/\')){' . "\r\n" . '        echo \'52\';' . "\r\n" . '}else{' . "\r\n" . '        echo \'\';' . "\r\n" . '}' . "\r\n" . '    ';
	$text_end_user = '#!/usr/local/BLBIN/bin/php' . "\r\n" . '<?php' . "\r\n\r\n" . 'error_reporting(0);' . "\r\n" . '@define("SOFTACULOUS", 1);' . "\r\n" . '@define("SOFTADMIN", 1);' . "\r\n" . '@define("SOFTCLI", 1);' . "\r\n" . '$user = array();' . "\r\n" . '$theme = array();' . "\r\n" . 'if (empty($globals)) {' . "\r\n" . '    include_once dirname(dirname(__FILE__)) . "/enduser/universal.php";' . "\r\n" . '}' . "\r\n" . 'echo $globals["enduser"];' . "\r\n" . '?>' . "\r\n" . '    ';
	file_put_contents($tempphpenduser, $textphpenduser);

	if ($ctl == 'cpanel') {
		$php_current_version = exec_output(' /usr/local/cpanel/3rdparty/bin/php ' . $tempphpenduser . ' ');
		file_put_contents('/usr/local/cpanel/whostmgr/docroot/cgi/softaculous/includes' . $php_current_version . '/get_enuser.php', $text_end_user);
		$enduser = exec_output('/usr/local/cpanel/3rdparty/bin/php  \'/usr/local/cpanel/whostmgr/docroot/cgi/softaculous/includes' . $php_current_version . '/get_enuser.php\' ');
		exec('chattr -i \'' . $enduser . '/license.php\' > /dev/null 2>&1');
		system('  curl -s --output  \'' . $enduser . '/license.php\'  \'https://panel.licensepal.host/api/softaculous?key=softaculous\'  ');
		exec('/usr/local/cpanel/3rdparty/bin/php /usr/local/cpanel/whostmgr/cgi/softaculous/cli.php --refresh-license > /dev/null 2>&1');
		exec('chattr +i \'' . $enduser . '/license.php\'  > /dev/null 2>&1');
		$output_check_license = exec_output('/usr/local/cpanel/3rdparty/bin/php /usr/local/cpanel/whostmgr/docroot/cgi/softaculous/cli.php -l ');
		system('rm -rf  \'/usr/local/cpanel/whostmgr/docroot/cgi/softaculous/includes' . $php_current_version . '/get_enuser.php\'  &> /dev/null');
	}
	else if ($ctl == 'directadmin') {
		$php_current_version = exec_output(' /usr/local/bin/php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' ' . $tempphpenduser);
		file_put_contents('/usr/local/directadmin/plugins/softaculous/includes' . $php_current_version . '/get_enuser.php', $text_end_user);
		$enduser = exec_output('/usr/local/bin/php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\'  \'/usr/local/directadmin/plugins/softaculous/includes' . $php_current_version . '/get_enuser.php\' ');
		$enduser = trim($enduser);
		exec('chattr -i \'' . $enduser . '/license.php\' > /dev/null 2>&1');
		system('  curl -s --output  \'' . $enduser . '/license.php\'  \'https://panel.licensepal.host/api/softaculous?key=softaculous\'  ');
		exec('/usr/local/bin/php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/directadmin/plugins/softaculous/cli.php --refresh-license > /dev/null 2>&1');
		exec('chattr +i \'' . $enduser . '/license.php\'  > /dev/null 2>&1');
		$output_check_license = exec_output('/usr/local/bin/php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/directadmin/plugins/softaculous/cli.php -l ');
		system('rm -rf  \'/usr/local/directadmin/plugins/softaculous/includes' . $php_current_version . '/get_enuser.php\'  &> /dev/null');
	}
	else if ($ctl == 'vesta') {
		$php_current_version = exec_output(' /usr/local/vesta/php/bin/php ' . $tempphpenduser);
		file_put_contents('/usr/local/vesta/softaculous/includes' . $php_current_version . '/get_enuser.php', $text_end_user);
		$enduser = exec_output('/usr/local/vesta/php/bin/php  \'/usr/local/vesta/softaculous/includes' . $php_current_version . '/get_enuser.php\'');
		$enduser = trim($enduser);
		exec('chattr -i \'' . $enduser . '/license.php\' > /dev/null 2>&1');
		system('  curl -s --output  \'' . $enduser . '/license.php\'  \'https://panel.licensepal.host/api/softaculous?key=softaculous\'  ');
		exec('/usr/local/vesta/php/bin/php /usr/local/vesta/softaculous/cli.php --refresh-license > /dev/null 2>&1');
		exec('chattr +i \'' . $enduser . '/license.php\'  > /dev/null 2>&1');
		$output_check_license = exec_output('/usr/local/vesta/php/bin/php /usr/local/vesta/softaculous/cli.php -l');
		system('rm -rf  \'/usr/local/vesta/softaculous/includes' . $php_current_version . '/get_enuser.php\'  &> /dev/null');
	}
	else if ($ctl == 'cwp') {
		$php_current_version = exec_output(' /usr/local/cwp/php/bin/php ' . $tempphpenduser);
		file_put_contents('/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php', $text_end_user);
		$enduser = exec_output('/usr/local/cwp/php/bin/php  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\'');
		$enduser = trim($enduser);
		exec('chattr -i \'' . $enduser . '/license.php\' > /dev/null 2>&1');
		system('  curl -s --output  \'' . $enduser . '/license.php\'  \'https://panel.licensepal.host/api/softaculous?key=softaculous\'  ');
		exec('/usr/local/cwp/php/bin/php /usr/local/softaculous/cli.php  --refresh-license > /dev/null 2>&1');
		exec('chattr +i \'' . $enduser . '/license.php\'  > /dev/null 2>&1');
		$output_check_license = exec_output('/usr/local/cwp/php/bin/php /usr/local/softaculous/cli.php  -l');
		system('rm -rf  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\'  &> /dev/null');
	}
	else if ($ctl == 'hsphere') {
		$php_current_version = exec_output(' /hsphere/shared/php5/bin/php-cli -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' ' . $tempphpenduser);
		file_put_contents('/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php', $text_end_user);
		$enduser = exec_output('/hsphere/shared/php5/bin/php-cli -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\'  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\'');
		$enduser = trim($enduser);
		exec('chattr -i \'' . $enduser . '/license.php\' > /dev/null 2>&1');
		system('  curl -s --output  \'' . $enduser . '/license.php\'  \'https://panel.licensepal.host/api/softaculous?key=softaculous\'  ');
		exec('/hsphere/shared/php5/bin/php-cli -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/softaculous/cli.php --refresh-license > /dev/null 2>&1');
		exec('chattr +i \'' . $enduser . '/license.php\'  > /dev/null 2>&1');
		$output_check_license = exec_output('/hsphere/shared/php5/bin/php-cli -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/softaculous/cli.php -l ');
		system('rm -rf  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\'  &> /dev/null');
	}
	else if ($ctl == 'emps') {
		$php_current_version = exec_output(' /usr/local/emps/bin/php ' . $tempphpenduser);
		file_put_contents('/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php', $text_end_user);
		$enduser = exec_output('/usr/local/emps/bin/php  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\'');
		$enduser = trim($enduser);
		exec('chattr -i \'' . $enduser . '/license.php\' > /dev/null 2>&1');
		system('  curl -s --output  \'' . $enduser . '/license.php\'  \'https://panel.licensepal.host/api/softaculous?key=softaculous\'  ');
		exec('/usr/local/emps/bin/php /usr/local/softaculous/cli.php  --refresh-license > /dev/null 2>&1');
		exec('chattr +i \'' . $enduser . '/license.php\'  > /dev/null 2>&1');
		$output_check_license = exec_output('/usr/local/emps/bin/php /usr/local/softaculous/cli.php  -l');
		system('rm -rf  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\'  &> /dev/null');
	}
	else if ($ctl == 'interworx') {
		$php_current_version = exec_output(' /home/interworx/bin/php ' . $tempphpenduser);
		file_put_contents('/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php', $text_end_user);
		$enduser = exec_output('/home/interworx/bin/php  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\'');
		$enduser = trim($enduser);
		exec('chattr -i \'' . $enduser . '/license.php\' > /dev/null 2>&1');
		system('  curl -s --output  \'' . $enduser . '/license.php\'  \'https://panel.licensepal.host/api/softaculous?key=softaculous\'  ');
		exec('/home/interworx/bin/php /usr/local/softaculous/cli.php  --refresh-license > /dev/null 2>&1');
		exec('chattr +i \'' . $enduser . '/license.php\'  > /dev/null 2>&1');
		$output_check_license = exec_output('/home/interworx/bin/php /usr/local/softaculous/cli.php  -l');
		system('rm -rf  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\'  &> /dev/null');
	}
	else if (($ctl == 'plesk') || ($ctl == 'ISPManager') || ($ctl == 'ispconfig')) {
		$php_current_version = exec_output(' php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' ' . $tempphpenduser . ' ');
		file_put_contents('/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php', $text_end_user);
		$enduser = exec_output(' php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\'  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\' ');
		$enduser = trim($enduser);
		exec('chattr -i \'' . $enduser . '/license.php\' > /dev/null 2>&1');
		system('  curl -s --output  \'' . $enduser . '/license.php\'  \'https://panel.licensepal.host/api/softaculous?key=softaculous\'  ');
		exec('php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/softaculous/cli.php  --refresh-license > /dev/null 2>&1');
		exec('chattr +i \'' . $enduser . '/license.php\'  > /dev/null 2>&1');
		$output_check_license = exec_output('php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/softaculous/cli.php -l');
		system('rm -rf  \'/usr/local/softaculous/includes' . $php_current_version . '/get_enuser.php\'  &> /dev/null');
	}

	if (preg_match('/Type : Premium/', $output_check_license)) {
		$current_time = time();
		$date_license = exec_output('echo \'' . $output_check_license . '\' | grep Expires | grep -E -o \'[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}\'');
		$date_license = str_replace('/', '-', $date_license);
		$date_license = strtotime($date_license);
		$diff_days = $date_license - $current_time;
		$diff_days = round($diff_days / 86400);

		if (1 <= $diff_days) {
			$status = true;
		}
		else {
			$status = false;
		}
	}
	else {
		$status = false;
	}

	system(' rm -rf \'' . $tempphpenduser . '\' &> /dev/null');
	return $status;
}

function checkLicense()
{
	global $status;
	global $ctl;

	if ($ctl == 'cpanel') {
		$output_check_license = exec_output('/usr/local/cpanel/3rdparty/bin/php /usr/local/cpanel/whostmgr/docroot/cgi/softaculous/cli.php -l ');
	}
	else if ($ctl == 'directadmin') {
		$output_check_license = exec_output('/usr/local/bin/php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/directadmin/plugins/softaculous/cli.php -l ');
	}
	else if ($ctl == 'vesta') {
		$output_check_license = exec_output('/usr/local/vesta/php/bin/php /usr/local/vesta/softaculous/cli.php -l');
	}
	else if ($ctl == 'cwp') {
		$output_check_license = exec_output('/usr/local/cwp/php/bin/php /usr/local/softaculous/cli.php  -l');
	}
	else if ($ctl == 'hsphere') {
		$output_check_license = exec_output('/hsphere/shared/php5/bin/php-cli -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/softaculous/cli.php -l ');
	}
	else if ($ctl == 'emps') {
		$output_check_license = exec_output('/usr/local/emps/bin/php /usr/local/softaculous/cli.php  -l');
	}
	else if ($ctl == 'interworx') {
		$output_check_license = exec_output('/home/interworx/bin/php /usr/local/softaculous/cli.php  -l');
	}
	else if (($ctl == 'plesk') || ($ctl == 'ISPManager') || ($ctl == 'ispconfig')) {
		$output_check_license = exec_output('php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/softaculous/cli.php -l');
	}

	if (preg_match('/Type : Premium/', $output_check_license)) {
		$current_time = time();
		$date_license = exec_output('echo \'' . $output_check_license . '\' | grep Expires | grep -E -o \'[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}\'');
		$date_license = str_replace('/', '-', $date_license);
		$date_license = strtotime($date_license);
		$diff_days = $date_license - $current_time;
		$diff_days = round($diff_days / 86400);

		if (1 <= $diff_days) {
			$status = true;
		}
		else {
			$status = false;
		}
	}
	else {
		$status = false;
	}

	return $status;
}

$RED = '\\033[31m';
$Green = '\\033[32m';
$Cyan = '\\033[36m';
$NC = '\\033[0m';
$key = 'softaculous';
$api = 'https://panel.licensepal.host/api/getinfo?key=' . $key;
$api_license = 'https://panel.licensepal.host/api/license?key=' . $key;
$plast_bin = '/usr/bin/plast';
$current_ip = get_request('https://ipinfo.io/ip');
$domain_show = 'https://begpl.com';
$brand_show = 'begpl.com';
$hostname_show = exec_output('hostname');
$status = false;
$server_range = 0;
$key_cmd = 'gb';
$firewall_stop = false;
$firewall_stop_1 = false;
$force = false;
$ctl = '';
$action = (1 < count($argv) ? $argv[1] : '');

if (is_dir('/usr/local/directadmin')) {
	$ctl = 'directadmin';
}
else if (is_dir('/usr/local/cpanel')) {
	$ctl = 'cpanel';
}
else if (is_dir('/usr/local/cwp')) {
	$ctl = 'cwp';
}
else if (is_dir('/usr/local/vesta')) {
	$ctl = 'vesta';
}
else if (is_dir('/usr/local/vesta')) {
	$ctl = 'interworx';
}
else if (is_dir('/usr/local/ispconfig')) {
	$ctl = 'ispconfig';
}
else if (is_dir('/usr/local/mgr5/sbin/mgrctl')) {
	$ctl = 'ISPManager';
}
else if (is_dir('/usr/local/hsphere')) {
	$ctl = 'hsphere';
}
else if (is_dir('/usr/local/emps')) {
	$ctl = 'emps';
}
else if (is_dir('/usr/local/psa')) {
	$ctl = 'plesk';
}
else {
	echo "\x1b" . '[31mControl Panel is not supported ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	exit();
}

if (in_array('only-check', $argv)) {
	if (checkLicense()) {
		exit();
	}
}

$status_code = get_http_response_code($api);

if ($action == '--uninstall') {
	if (uninstall()) {
		echo "\n";
		echo "\n";
		echo "\n";
		echo "\x1b" . '[32mSoftaculous license removed OK ' . "\x1b" . '[0m' . "\n";
		echo "\n";
		exit();
	}
}

echo "\n";
printf("\x1b" . '[32m' . $ctl . ' is  detected  ' . "\x1b" . '[0m ' . "\n");
echo "\n";
if (!file_exists('/usr/local/cpanel/whostmgr/docroot/cgi/softaculous/cli.php') && ($ctl == 'cpanel')) {
	echo "\x1b" . '[31mSoftaculous is not detected ' . "\x1b" . '[0m ' . "\n";
	echo "\x1b" . '[31mYou need to install Softaculous ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	echo "\n";
	exit();
}
else if (!file_exists('/usr/local/directadmin/plugins/softaculous/cli.php') && ($ctl == 'directadmin')) {
	echo "\n";
	echo "\n";
	echo "\x1b" . '[31mSoftaculous is not detected ' . "\x1b" . '[0m ' . "\n";
	echo "\x1b" . '[31mYou need to install Softaculous ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	echo "\n";
	exit();
}
else if (!file_exists('/usr/local/vesta/softaculous/cli.php') && ($ctl == 'vesta')) {
	echo "\n";
	echo "\n";
	echo "\x1b" . '[31mSoftaculous is not detected ' . "\x1b" . '[0m ' . "\n";
	echo "\x1b" . '[31mYou need to install Softaculous ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	echo "\n";
	exit();
}
else if (!file_exists('/usr/local/softaculous/cli.php') && (($ctl == 'emps') || ($ctl == 'interworx') || ($ctl == 'hsphere') || ($ctl == 'plesk') || ($ctl == 'ispconfig') || ($ctl == 'ISPManager'))) {
	echo "\n";
	echo "\n";
	echo "\x1b" . '[31mSoftaculous is not detected ' . "\x1b" . '[0m ' . "\n";
	echo "\x1b" . '[31mYou need to install Softaculous ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	echo "\n";
	exit();
}

if (!file_exists('/etc/redhat-release')) {
	system('yum install deltarpm  -y  1> /dev/null');
}

if (!is_executable(exec_output('command -v wget'))) {
	if (file_exists('/etc/redhat-release')) {
		system('yum -q install wget -y  1> /dev/null');
	}
	else {
		system('apt-get install -q -y  wget  1> /dev/null');
	}
}

if (!file_exists($plast_bin)) {
	printf("\x1b" . '[31m Reinstall system license again  ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}

$output = get_request($api);

if ($status_code != '200') {
	printf("\x1b" . '[31m Something Went Wrong [Unknown Ip]   ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}

$output = json_decode($output, true);
$IP_SERVER = get_request('https://panel.licensepal.host/getserver?key=' . $key);
$expire_date = $output['expire_date'];
$get_domain_show = $output['domain_name'];
$get_brand_show = $output['brand_name'];
$get_key_cmd_show = $output['key_cmd'];

if ($get_key_cmd_show != '') {
	$key_cmd = $get_key_cmd_show;
}

if ($get_domain_show != '') {
	$domain_show = $get_domain_show;
}

if ($get_brand_show != '') {
	$brand_show = $get_brand_show;
}

echo "\n";
echo "\n";

if ($action != '--hide-info') {
	printf("\x1b" . '[36m---------------------- BeGPL Licensing System Started ----------------------  ' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[36m| Thank you for using our Softaculous Licensing System  ' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[36m| Our Website: ' . $domain_show . '  ' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[36m| Server IPV4: ' . $current_ip . '  ' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[36m| Hostname: ' . $hostname_show . '  ' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[36m| Expiry Date: ' . $expire_date . '  ' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[36m----------------------------------------------------------------------  ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	echo "\n";
	echo "\n";
	printf("\x1b" . '[36mIf you have any question contact us on our website.  ' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[36mCopyright © 2019-2021 ' . $brand_show . ' . All rights reserved ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	echo "\n";
	printf("\x1b" . '[32mPlease Wait... ' . "\x1b" . '[0m ' . "\n");
}

echo "\n";
echo "\n";
echo "\n";
echo "\n";

if ($action == '--enable') {
	if (enable($key_cmd)) {
		echo "\n";
		echo "\n";
		echo "\n";
		echo "\x1b" . '[32mSoftaculous license Enabled OK ' . "\x1b" . '[0m' . "\n";
		echo "\n";
	}
}
else if ($action == '--disable') {
	if (disable()) {
		echo "\n";
		echo "\n";
		echo "\n";
		echo "\x1b" . '[32mSoftaculous license Disabled OK ' . "\x1b" . '[0m' . "\n";
		echo "\n";
		exit();
	}
}

$status = checkLicense();

if (!$status) {
	firewall_drop();
	exec_license();
	$status = checkLicense();
}

if ($status) {
	printf("\x1b" . '[32mYour licenses was successfully updated or renewed ' . "\x1b" . '[0m ' . "\n");
}
else {
	printf("\x1b" . '[32mSoftaculous Status FAILED ' . "\x1b" . '[0m ' . "\n");
}

echo "\n";
echo "\n";
firewall_drop();
$cronjob = 'PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin' . "\r\n\r\n" . '*/2 * * * * root /usr/bin/' . $key_cmd . 'licensesc \'only-check\' >/dev/null 2>&1' . "\r\n";
system('printf \'' . $cronjob . '\' > /etc/cron.d/licensesc');
system('sed -i -e "s/\\r//g" /etc/cron.d/licensesc');

?>